package com.sz.biz.logistics.core.service.impl;

import com.sz.biz.logistics.core.entity.ProductServiceRegionRel;
import com.sz.biz.logistics.core.service.ProductServiceRegionRelService;
import com.sz.biz.logistics.core.dto.ProductServiceRelRegionInfo;
import com.sz.common.base.dao.ParamData;
import com.sz.common.base.service.AbstractService;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Function:  ProductServiceRegionRelServiceImpl <br>
 * Author: jifeixing <br>
 * Date: 2017-10-12 14:58:00
 */
@org.springframework.stereotype.Service
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public class ProductServiceRegionRelServiceImpl extends AbstractService implements ProductServiceRegionRelService {

    @Override
    protected String getMapperNamespace() {
        return "ProductServiceRegionRelMapper";
    }

    @Override
    public void save(ProductServiceRegionRel productServiceRegionRel) {
        dao.save(getSqlName("insertSelective"), productServiceRegionRel);
    }

    /**
     * 根据产品服务id查新服务范围信息
     * @param psId
     * @param regionType
     * @return
     */
    @Override
    public List<ProductServiceRelRegionInfo> findByPsId(Integer psId, String regionType) {
        ParamData paramData = new ParamData();
        paramData.put("psId", psId);
        paramData.put("regionType", regionType);
        return dao.findForList(getSqlName("findByPsId"), paramData, ProductServiceRelRegionInfo.class);
    }

    @Override
    public List<ProductServiceRegionRel> findRegionByPsId(Integer psId){
        return dao.findForList(getSqlName("findRegionByPsId"), psId, ProductServiceRegionRel.class);
    }

    @Override
    public void batchDeleteByPsIds(List<Integer> psIds){
        ParamData paramData = new ParamData();
        paramData.put("psIds", psIds);
        dao.delete(getSqlName("batchDeleteByPsIds"), paramData);
    }

    @Override
    public void updatePsId(Integer oldPsId, Integer newPsId, Integer newProductId) {
        ParamData paramData = new ParamData();
        paramData.put("oldPsId", oldPsId);
        paramData.put("newPsId", newPsId);
        paramData.put("newProductId", newProductId);
        dao.update(getSqlName("updateByPsId"), paramData);
    }
}
